﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sudoku
{
    public partial class SpremanjeRekordaForma : Form
    {
        private int p1;
        private int p2;
        private string p3;

        public SpremanjeRekordaForma()
        {
            InitializeComponent();
        }

        public SpremanjeRekordaForma(int p1, int p2, string p3)
        {
            // TODO: Complete member initialization
            InitializeComponent();
            this.p1 = p1;
            this.p2 = p2;
            this.p3 = p3;
        }

        private void btnOtkazi_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Dali ste sigurni ?", "Otkaži spremanje novog rekorda", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                this.Close();
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        private void saveBestScore()
        {
            Rekord r = new Rekord();
            r.Id = p1;
            r.Vrijeme = p2;
            r.Ime = txtIme.Text;
            r.Prezime = txtPrezime.Text;
            r.Level = p3;
            r.Datum = DateTime.Now;

            DAL.DAL dal = DAL.DAL.Instanca;
            dal.kreirajKonekciju("127.0.0.1", "sudoku", "root", "");
            DAL.DAL.RekordDAO d = new DAL.DAL.RekordDAO();
            d.update(r);
            dal.terminirajKonekciju();
        }
        private void btnPotvrdi_Click(object sender, EventArgs e)
        {
            if(txtIme.Text == "" || txtPrezime.Text == "")
            {
                toolStripStatusLabel1.Text = "Podaci nisu unešeni.";
                return;
            }
            else
            {
                saveBestScore();
                MessageBox.Show("Novi rekord uspješno spremljen.");
                this.Close();
            }
        }

        private void txtIme_TextChanged(object sender, EventArgs e)
        {
            this.toolStripStatusLabel1.Text = "";
        }

        private void txtPrezime_TextChanged(object sender, EventArgs e)
        {
            this.toolStripStatusLabel1.Text = "";
        }
    }
}
